package team.seekers.hula.common.entity.enums.course;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * date: 2022/5/14 10:00
 *
 * @author GH
 * QQ 1124813753
 */
@Getter
@AllArgsConstructor
public enum CourseSortTypeEnum {
    /**按时间排序*/
    TIME(0, "按时间排序"),
    /**按学习人数排序*/
    STUDENT_COUNT(1, "按学习人数排序"),
    /**按价格排序*/
    PRICE(2, "按价格排序"),
    /**综合排序*/
    COMPREHENSIVENESS(3, "综合排序"),
    /**其他情况*/
    OTHER(-1, "其他情况");

    @JsonValue
    private int code;
    private String content;

    @JsonCreator
    public static CourseSortTypeEnum getByCode(int code) {
        return Arrays.stream(values()).filter(e -> e.getCode() == code).findFirst().orElse(OTHER);
    }

    public static CourseSortTypeEnum getByContent(String content) {
        return Arrays.stream(values()).filter(e -> e.getContent().equalsIgnoreCase(content)).findFirst().orElse(OTHER);
    }
}
